
package com.eascs.crm.loanstart.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.admin.common.controller.BaseMasterViewController;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.common.util.StringUtil;
import com.eascs.crm.common.custnew.entity.CustomerEntity;
import com.eascs.crm.common.custnew.service.CustomerService;
import com.eascs.site.view.ViewContext;
import com.eascs.tag.MenuTag;

@Controller
@RequestMapping("/loanstart")
public class LoanStartController extends BaseMasterViewController {
	private final Logger logger = LoggerFactory.getLogger(LoanStartController.class);
	@Reference
	CustomerService customerService;

	@Override
	public void preHandle() {
		super.preHandle();
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "loanManage1");
	}

	/**
	 * @Title: index
	 * @Description: 申请借款-查询客户
	 * @author 张庆奇
	 * @return
	 * @return String
	 * @throws @date
	 *             2017年7月3日 下午2:17:31
	 */
	@RequestMapping(value = "/index", method = RequestMethod.GET)
	public String index(String idCard) {
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "apply");
		if(StringUtil.isNotBlank(idCard)){
		   idCard=idCard.trim();
		}
		ViewContext.put("idCard", idCard);
		logger.info("idCard:", idCard);
		return "loanstart/index";

	}

	/**
	 * @Title: search
	 * @Description: 根据查询结果跳转到申请借款-编辑客户信息 或者申请借款-增加客户信息
	 * @author 张庆奇
	 * @param idCard
	 * @return
	 * @return String
	 * @throws @date
	 *             2017年7月3日 下午2:17:44
	 */
	@RequestMapping(value = "/search")
	public String search(String idCard) {
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "apply_search");
		if(StringUtil.isNotBlank(idCard)){
			   idCard=idCard.trim();
		}
		ViewContext.put("idCard", idCard);
		CustomerEntity basic = customerService.queryCustomerEntityByIdCard(idCard);
		String title = "";
		if (basic == null) {
			basic=new CustomerEntity();
			title = "添加";
		} else {
			title = "编辑";
		}
		ViewContext.put("idCard", idCard);
		ViewContext.put("title", title);
		ViewContext.put("vo", basic);
		return "/loanstart/editLoan";

	}

}
